﻿using System;
using Abp.Castle.Logging.Log4Net;
using Abp.Web;
using Castle.Facilities.Logging;
using log4net;

namespace AVIS.OutBound.Web
{
    public class MvcApplication : AbpWebApplication<OutBoundWebModule>
    {
        protected override void Application_Start(object sender, EventArgs e)
        {
            AbpBootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(
                f => f.UseAbpLog4Net().WithConfig(Server.MapPath("log4net.config"))
            );

            base.Application_Start(sender, e);
        }

        protected override void Application_BeginRequest(object sender, EventArgs e)
        {
            MDC.Set("requestId", Guid.NewGuid().ToString("N"));
            MDC.Set("serverIp", System.Web.HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"]);
        }

        protected override void Application_EndRequest(object sender, EventArgs e)
        {
            MDC.Remove("requestId");
            MDC.Remove("serverIp");
        }
    }
}
